﻿using UnityEngine;
using System.Collections;


public enum AwardType
{
    Gun,        // 枪
    DualSword  //双手剑
}

public class AwardSphere : MonoBehaviour {

    public AwardType Type;
    public bool startMove;
    private GameObject player;
    public float speed = 1.4f;
	// Use this for initialization
	void Start () {

        GetComponent<Rigidbody>().velocity = new Vector3(Random.Range(-5,5),0,Random.Range(-5,5));
	}
	
	// Update is called once per frame
	void Update () {

        if (startMove)
        {
            if(speed<10)
            speed += Time.deltaTime ;
            if (player)
            {
                transform.position = Vector3.Lerp(transform.position, player.transform.position + Vector3.up, speed * Time.deltaTime);

                if (Vector3.Distance(player.transform.position + Vector3.up, transform.position) <= 0.3f)
                {
                    player.GetComponent<GetAwardSphere>().GetSphere(Type);
                    Destroy(gameObject);
                }
            }
        }


	}

    // 碰撞检测的方法
    void OnCollisionEnter(Collision other)
    {

        if (other.collider.tag.CompareTo(Tags.ground)==0)
        {
            GetComponent<Rigidbody>().isKinematic = true;
            SphereCollider col=this.GetComponent<SphereCollider>();
            col.radius = 3;
            col.isTrigger = true;
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag.CompareTo(Tags.player) == 0)
        {

            startMove = true;
            player = other.gameObject;
        }
    }



}
